﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Expect.Core.IO;

namespace Expect.Core.Test.IO
{
    [TestClass]
    public class TextReaderTest
    {
        [TestMethod]
        public void ExecuteFromText()
        {
            var res = SampleSpecificationCheck.ExecuteFromText(
                this,
                new TextSpecificationReader(),
                "SampleTextSpec.txt"
                );
            Assert.AreEqual("bla bla bla", res.ContainerBaseClass);
            Assert.AreEqual("toto", res.GetSetupFrom);
            Assert.AreEqual("titi", res.GetTeardownFrom);
        }

        [TestMethod]
        public void ExecuteContainerFromText()
        {
            string specText = Helper.LoadFromRessourceFile("ContainerTextSpec.txt");
            var res = new TextSpecificationReader().ReadSpecification("ContainerTextSpec.txt", specText);
            
            Assert.AreEqual("bla bla bla", res.ContainerBaseClass);
            Assert.AreEqual(9, res.Specification.Fixtures.Count);
            Assert.AreEqual("toto", res.GetSetupFrom);
            Assert.AreEqual("titi", res.GetTeardownFrom);
        }

        [TestMethod]
        public void ExecuteFromStream()
        {
            var res = SampleSpecificationCheck.ExecuteFromStream(
                this,
                new TextSpecificationReader(),
                "SampleTextSpec.txt"
                );
            Assert.AreEqual("bla bla bla", res.ContainerBaseClass);
            Assert.AreEqual("toto", res.GetSetupFrom);
            Assert.AreEqual("titi", res.GetTeardownFrom);
        }

        [TestMethod]
        public void Lecture_Spec_Complexe()
        {
            var spec = SampleSpecificationCheck.ReadSpecification(new TextSpecificationReader(), "ComplexSpec.txt");

            Assert.IsNotNull(spec.Setup != null, "Setup is not defined");
            Assert.AreEqual(4, spec.Setup.Fixtures.Count, "Setup is invalid");

            Assert.IsNotNull(spec.Teardown != null, "Teardown is not defined");
            Assert.AreEqual(1, spec.Teardown.Fixtures.Count, "Teardown is invalid");

            Assert.IsNotNull(spec.ChildSpecs != null, "Child specs are not defined");
            Assert.AreEqual(2, spec.ChildSpecs.Count, "Child specs are invalid");
            Assert.AreEqual(2, spec.ChildSpecs[0].Fixtures.Count, "Child specs fixtures are invalid");
            Assert.AreEqual(3, spec.ChildSpecs[1].Fixtures.Count, "Child specs fixtures are invalid");
        }
    }
}
